clear all
set more off
cd ""

use "sample.dta", clear

tab rel_time, gen(rel_w)
forvalue i = 1/31 {
gen rel_w`i'_D = rel_w`i' * faction
}

gen rel_w11_D_21 = rel_w11_D*21
forvalue i = 12/31 {
gen diff_Drel`i'_11 = rel_w`i'_D - rel_w11_D
}

***********
* Panel A1
***********

reghdfe in_confn14 rel_w11_D_21 diff_Drel* treat_csm wdsp temp prcp if prov_age >= 61, absorb(i.city_code#i.faction i.time#i.faction i.prov_code#c.time#i.faction) cluster(time)

reghdfe d_movewithin rel_w11_D_21 diff_Drel* treat_csm wdsp temp prcp if prov_age >= 61, absorb(i.city_code#i.faction i.time#i.faction i.prov_code#c.time#i.faction i.prov_code#c.time2#i.faction) cluster(time)

reghdfe bdindexS7_std rel_w11_D_21 diff_Drel* treat_csm wdsp temp prcp if prov_age >= 61, absorb(i.city_code#i.faction i.time#i.faction i.prov_code#c.time#i.faction) cluster(time)

***********
* Panel A2
***********

reghdfe in_confn14 rel_w11_D_21 diff_Drel* treat_csm wdsp temp prcp if prov_age <= 65, absorb(i.city_code#i.faction i.time#i.faction i.prov_code#c.time#i.faction) cluster(time)

reghdfe d_movewithin rel_w11_D_21 diff_Drel* treat_csm wdsp temp prcp if prov_age <= 65, absorb(i.city_code#i.faction i.time#i.faction i.prov_code#c.time#i.faction i.prov_code#c.time2#i.faction) cluster(time)

reghdfe bdindexS7_std rel_w11_D_21 diff_Drel* treat_csm wdsp temp prcp if prov_age <= 65, absorb(i.city_code#i.faction i.time#i.faction i.prov_code#c.time#i.faction) cluster(time)

**********
* Panel B
**********

replace prov_tenure = prov_tenure - 5 if prov_tenure > 5

reghdfe in_confn14 rel_w11_D_21 diff_Drel* treat_csm wdsp temp prcp if prov_tenure > 1, absorb(i.city_code#i.faction i.time#i.faction i.prov_code#c.time#i.faction) cluster(time)

reghdfe d_movewithin rel_w11_D_21 diff_Drel* treat_csm wdsp temp prcp if prov_tenure > 1, absorb(i.city_code#i.faction i.time#i.faction i.prov_code#c.time#i.faction i.prov_code#c.time2#i.faction) cluster(time)

reghdfe bdindexS7_std rel_w11_D_21 diff_Drel* treat_csm wdsp temp prcp if prov_tenure > 1, absorb(i.city_code#i.faction i.time#i.faction i.prov_code#c.time#i.faction) cluster(time)

***********
* Panel C1
***********

gen prov_faction = inlist(prov_code,13,14,22,33,35,36,43,44,46,53,61)

reghdfe in_confn14 rel_w11_D_21 diff_Drel* treat_csm wdsp temp prcp if prov_faction == 1, absorb(i.city_code#i.faction i.time#i.faction i.prov_code#c.time#i.faction) cluster(time)

reghdfe d_movewithin rel_w11_D_21 diff_Drel* treat_csm wdsp temp prcp if prov_faction == 1, absorb(i.city_code#i.faction i.time#i.faction i.prov_code#c.time#i.faction i.prov_code#c.time2#i.faction) cluster(time)

reghdfe bdindexS7_std rel_w11_D_21 diff_Drel* treat_csm wdsp temp prcp if prov_faction == 1, absorb(i.city_code#i.faction i.time#i.faction i.prov_code#c.time#i.faction) cluster(time)

***********
* Panel C2
***********

reghdfe in_confn14 rel_w11_D_21 diff_Drel* treat_csm wdsp temp prcp if prov_faction == 0, absorb(i.city_code#i.faction i.time#i.faction i.prov_code#c.time#i.faction) cluster(time)

reghdfe d_movewithin rel_w11_D_21 diff_Drel* treat_csm wdsp temp prcp if prov_faction == 0, absorb(i.city_code#i.faction i.time#i.faction i.prov_code#c.time#i.faction i.prov_code#c.time2#i.faction) cluster(time)

reghdfe bdindexS7_std rel_w11_D_21 diff_Drel* treat_csm wdsp temp prcp if prov_faction == 0, absorb(i.city_code#i.faction i.time#i.faction i.prov_code#c.time#i.faction) cluster(time)
